﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using PublicTemplateEditor.Mold;
using PublicTemplateEditor.Helper;

namespace PublicTemplateEditor.DataAccess
{
    /// <summary>
    /// 换肤
    /// </summary>
    public class ThemeDA
    {
        #region 换肤
        //获取某个样式
        private static string getThemeSQL = "select id,opacity,bright,color,saturation,name,isdefault,iscustom from m_theme where id=0";
        //更新自定义样式
        private static string updateThemeSQL = "update m_theme set opacity={0},bright={1},color={2},saturation={3} where iscustom=1 and id=0";
        #endregion

        /// <summary>
        /// 获取主题
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static ThemeInfo GetTheme()
        {
            ThemeInfo theme = null;

            object[] objList = CommonAccess.sqlite.GetRow(getThemeSQL);
            if (objList == null) return null;

            if (objList != null)
            {
                theme = new ThemeInfo() 
                {  Bright = CommonHelper.ConvertToDouble(objList[2]),
                   Opacity = CommonHelper.ConvertToDouble(objList[1]) == 0 ? 1 : CommonHelper.ConvertToDouble(objList[1]),
                   Color = CommonHelper.ConvertToDouble(objList[3]),
                   Saturation = CommonHelper.ConvertToDouble(objList[4])
                }; 
            }

            return theme;
        }

        /// <summary>
        /// 更新样式
        /// </summary>
        /// <param name="theme"></param>
        public static void UpdateTheme(ThemeInfo theme)
        {
            string sql = string.Format(updateThemeSQL, theme.Opacity, theme.Bright, theme.Color, theme.Saturation);
            CommonAccess.sqlite.ExeSql(sql);
        }
    }

   
}
